package com.xperblueray.stepbystep.service.impl;

import com.xperblueray.stepbystep.model.SbsMood;
import com.xperblueray.stepbystep.producer.SbsMoodProducer;
import com.xperblueray.stepbystep.repository.SbsMoodRepository;
import com.xperblueray.stepbystep.service.SbsMoodService;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Destination;

@Service
public class SbsMoodServiceImpl implements SbsMoodService {
    @Resource
    SbsMoodRepository sbsMoodRepository;

    //队列
    private static Destination destination = new ActiveMQQueue("sbs.queue.asyn.save");

    @Resource
    SbsMoodProducer sbsMoodProducer;

    @Override
    public SbsMood save(SbsMood sbsMood) {
        return sbsMoodRepository.save(sbsMood);
    }

    @Override
    public String asynSave(SbsMood sbsMood) {
        // 往队列sbs.queue.asyn.save推送消息，消息内容为说说实体
        sbsMoodProducer.sendMessage(destination, sbsMood);

        return "success";
    }
}
